import {login,findById} from "../service/user"
export default {
    namespaced: true,
    state: {
        userName: "",
        userRealName: "",
        userPhone: "",
        userGender: "",
        userPwd: "",
        user:{},
        userSession:{},
        dialogVisible: false,
    },
    mutations: {
        setUserName(state,userName){
            state.userName = userName;
        },
        setUserRealName(state,userRealName){
            state.userRealName = userRealName;
        },
        setUserPhone(state,userPhone){
            state.userPhone = userPhone;
        },
        setUserGender(state,userGender){
            state.userGender = userGender;
        },
        setUserPwd(state,userPwd){
            state.userPwd = userPwd;
        },
        setUser(state,user){
            state.user = user;
        },
        setUserSession(state,userSession){
            state.userSession = userSession;
        },
        setDialogVisible(state,dialogVisible){
            state.dialogVisible = dialogVisible;
        },
    },
    actions: {
        async login({commit},{userName,userPwd}){
            let response = await login(userName,userPwd);
            if (response.status === 1) {
                commit("setUserSession", response.data);
            }
            return response.status;
        },
        async findById({commit},userId){
            let response = await findById(userId);
            if (response.status === 1) {
                commit("setUser", response.data);
            }
            return response.status;
        }

    }
}